import com.aliasi.lm.TokenizedLM
import com.aliasi.tokenizer.IndoEuropeanTokenizerFactory
import com.aliasi.lm.TrieCharSeqCounter
import com.google.common.collect.Sets
/**
 * Created with IntelliJ IDEA.
 * User: neradis
 * Date: 5/2/12
 * Time: 3:17 PM
 * To change this template use File | Settings | File Templates.
 */
class PrintNgramsTest extends GroovyTestCase {

    static final TEST_SENTENCE = "one two two three three three " +
                                 "un to to tre tre tre " +
                                 "eins zwei zwei drei drei drei"

    static final TEST_CHAR_SEQ = "aabaabaacaac"
    TokenizedLM tokenCounter
    TrieCharSeqCounter charCounter


    void setUp() {
        tokenCounter = createTokenCounter()
        charCounter = createCharCounter()
    }

    TokenizedLM createTokenCounter() {
        TokenizedLM counter = new TokenizedLM(IndoEuropeanTokenizerFactory.INSTANCE, 1);
        counter.train(TEST_SENTENCE)
        counter
    }

    TrieCharSeqCounter createCharCounter() {
        TrieCharSeqCounter counter = new TrieCharSeqCounter(4);
        counter.incrementSubstrings(TEST_CHAR_SEQ);
        counter
    }

    void testNgramCounter() {
        def freqTerms = tokenCounter.frequentTermSet(1, 3)
        assert freqTerms.every { ["three", "tre", "drei"].contains(it.object[0]) }
    }

    void testCharCounter() {
        def bigrams = charCounter.topNGrams(2, Integer.MAX_VALUE)
        Map<Integer, Set<String>> countNgramMap = [:]
        bigrams.each {ngram, count ->
            if (!countNgramMap[count]) countNgramMap[count] = Sets.newHashSet()
//            if (!countNgramMap.containsKey(count)) countNgramMap[count] = Sets.newHashSet()
            countNgramMap[count].add(ngram)
        }
        assert countNgramMap[4].contains("aa")
    }

    void testCollectNgramsByCount() {




    }




}
